﻿// JScript 文件
//初始化
    function GetTableInfo(tableObj)
    {
        if(tableObj==null)
        {
            return null;
        }
        var allCells = new Array();
        
        //根据表的内容初始化 allCells
//        var tableObj  = document.getElementById("datatable");
        var rowNum = tableObj.rows.length;
        for (i=0; i < rowNum; i++)               //遍历每行
        {
            var tr = tableObj.rows[i];
            var cellNum = tr.cells.length;
            var startCell = 0;
            for(j=0;j<cellNum;j++)  //每个单元格
            {
                var td = tableObj.rows[i].cells[j];
                var tempStart = startCell;
                // 根据每个单元格跨行，列的情况重新进行序号定义
                for(y=tr.rowIndex;y<tr.rowIndex+td.rowSpan;y++)
                {
                    startCell = tempStart;
                    for(x=0;x<td.colSpan;x++)
                    {
                        if(allCells[y]==null)
                        {
                            allCells[y] = new Array();
                        }
                        while(allCells[y][startCell]!=null)
                        {
                            startCell++;
                        }

                        //Sign 行列单元格的标记，所属TD
                        allCells[y][startCell] ={Sign: i+','+j,Text:td.innerText,
                        Align:td.style.textAlign=="" ? "center":td.style.textAlign,
                        Type:td.style.textAlign=="right"?"number":"text"};
                        if(td.rect == null)
                        {
                            tempStart = startCell;
                            td.rect = {left:startCell,top:y,right:startCell,botton:y};
                        }

                    }
                }
            }
        }
//        //打印调试信息
//        var showdt = document.getElementById('debugView');
//        for(i=0;i<allCells.length;i++)
//        {
//            var lastIndex = showdt.rows.length;
//            showdt.insertRow(lastIndex);
//            for(j=0;j<allCells[i].length;j++)
//            {
//                showdt.rows[lastIndex].insertCell(j);
//                showdt.rows[lastIndex].cells[j].innerHTML=allCells[i][j].Sign +"&nbsp;:"+allCells[i][j].Text+"&nbsp;："+allCells[i][j].Align+"&nbsp;:"+allCells[i][j].Type;
//            }
//        }


        return allCells;
    }
